<?php

class SucursalesController extends AppController {

    public $layout = 'default';
    public $name = 'Sucursales';
    public $uses = array('Sucursale');
    public $helpers = array('Html', 'Form');
    public $components = array('Session');

    public function index(){
	 $this->paginate = array('Sucursale' => array('limit' => 50));
     $this->set('data', $this->paginate('Sucursale'));
	}

    public function insertar(){
	
	if(!empty($this->data)):
            if ($this->Sucursale->save($this->data)) {
                $this->Session->setFlash('Registro de Maquinaria completado');
                $this->redirect(array('action' => 'index'), null, true);
            } else {
                $this->Session->setFlash('No se pudo registrar la maquinaria!!!!!');
                $this->redirect(array('action' => 'index'), null, true);
            }
    endif;
	}
	function editar($id = null){
               
      $this->Sucursale->id = $id;
      if (!$id) {
         $this->Session->setFlash('No existe tal registro');
         $this->redirect(array('action' => 'index'), null, true);
                }
      if (empty($this->data)) {
         $this->data = $this->Sucursale->read(); 
    //     debug($this->data);exit;
      } else {
        if ($this->Sucursale->save($this->data)) {
        $this->Session->setFlash('Los datos fueron modificados');
         $this->redirect(array('action' => 'index'), null, true);
        } else {
        $this->Session->setFlash('no se pudo modificar!!');
                }
      }
    }
     public function eliminar($id = null)
    {
        if (!$id) {
            $this->Session->setFlash('id Invalida para borrar');
            $this->redirect(array('action' => 'index'));
        }
        
        if ($this->Sucursale->delete($id)) {
            $this->Session->setFlash('Registro eliminado');
            $this->redirect(array('action' => 'index'));
        }
    }

}

?>